//
//  FindDetailViewController.m
//  Project_A Gary
//
//  Created by leilei on 16/4/8.
//  Copyright © 2016年 www.lei.com. All rights reserved.
//

#import "FindDetailViewController.h"
#import "TitleViewTwo.h"

#import "ParameterCollectionViewCell.h"
#import "FindPictureCollectionViewCell.h"
#import "ArticleCollectionViewCell.h"




@interface FindDetailViewController ()<TitleViewTwoDelegate, UICollectionViewDataSource, UICollectionViewDelegate, UIScrollViewDelegate>

@property (nonatomic, retain)TitleViewTwo *titleVTwo;
@property (nonatomic, retain)UICollectionView *detailCollection;

@end

@implementation FindDetailViewController

-(void)dealloc
{
    [_findDetailId release];
    [_titleVTwo release];
    [_detailCollection release];
    
    [_priceRange release];
    [super dealloc];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    
    // 将tabBar 设置为隐藏
    self.tabBarController.tabBar.translucent = NO;
    // 将tabBar 设置为显示
    self.navigationController.navigationBar.translucent = YES;
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    [self createTitleView];
    [self createCollectionView];
    
}






#pragma mark - 创建collectionView
- (void)createCollectionView
{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(BOUNDS_WIDTH, BOUNDS_HEIGHT - 64 - 50 - 49);
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.minimumInteritemSpacing = 0;
    flowLayout.minimumLineSpacing = 0;
    
    self.detailCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 64 + 50, BOUNDS_WIDTH, BOUNDS_HEIGHT - 64 - 50 - 49) collectionViewLayout:flowLayout];
    [self.view addSubview:self.detailCollection];
    self.detailCollection.backgroundColor = [UIColor colorWithRed:236 / 255.0 green:236 / 255.0 blue:236 / 255.0 alpha:1];
    self.detailCollection.delegate = self;
    self.detailCollection.dataSource = self;
    self.detailCollection.pagingEnabled = YES;
    
    [self.detailCollection registerClass:[ParameterCollectionViewCell class] forCellWithReuseIdentifier:@"ParameterCollectionViewCell"];
    [self.detailCollection registerClass:[FindPictureCollectionViewCell class] forCellWithReuseIdentifier:@"FindPictureCollectionViewCell"];
    [self.detailCollection registerClass:[ArticleCollectionViewCell class] forCellWithReuseIdentifier:@"ArticleCollectionViewCell"];
    
    [flowLayout release];
    [_detailCollection release];
    
}

#pragma mark - collectionView的两个协议方法
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 3;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (0 == indexPath.item) {
        ParameterCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ParameterCollectionViewCell" forIndexPath:indexPath];
        
        cell.ParameterId = self.findDetailId;
        cell.priceRange = self.priceRange;
        NSLog(@"11%@", cell.ParameterId);
        cell.backgroundColor = [UIColor colorWithRed:236 / 255.0 green:236 / 255.0 blue:236 / 255.0 alpha:1];
        return cell;
    } else if (1 == indexPath.item) {
        FindPictureCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"FindPictureCollectionViewCell" forIndexPath:indexPath];
        
        cell.findPicId = self.findDetailId;
        cell.backgroundColor = [UIColor colorWithRed:236 / 255.0 green:236 / 255.0 blue:236 / 255.0 alpha:1];
        return cell;
    } else {
        ArticleCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ArticleCollectionViewCell" forIndexPath:indexPath];
        
        cell.articleId = self.findDetailId;
        cell.backgroundColor = [UIColor colorWithRed:236 / 255.0 green:236 / 255.0 blue:236 / 255.0 alpha:1];
        return cell;
        
    }
        
}
//- (void)viewDidAppear:(BOOL)animated
//{
//    self.tabBarController.tabBar.hidden = NO;
//    
//}





#pragma mark - 创建titleView
- (void)createTitleView
{
    TitleViewTwo *titleTwo = [TitleViewTwo creatTitleViewTwo];
    [self.view addSubview:titleTwo];
    titleTwo.titleArray = @[@"参配", @"图片", @"文章"];
    self.titleVTwo = titleTwo;
    self.titleVTwo.delegates = self;
    
}

#pragma mark - 实现两个titleView的方法
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    NSInteger page = scrollView.contentOffset.x / BOUNDS_WIDTH;
    [self.titleVTwo setSelectedIndex:page];
}

#pragma mark - titleView的协议方法
- (void)TitleViewTwo:(TitleViewTwo *)title selectedIndexChanged:(NSInteger)index
{
    [self.detailCollection scrollRectToVisible:CGRectMake(index * BOUNDS_WIDTH, 0, BOUNDS_WIDTH, BOUNDS_HEIGHT) animated:YES];
    
}








- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
